package com.mililoan.persist.system.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.mililoan.common.dao.AbstractBaseDao;
import com.mililoan.model.system.Function;
import com.mililoan.persist.system.FuncDao;

/**
 * 功能表操作接口类
 * @author mwei
 *
 */
@Repository("funcDao")
public class FuncDaoImpl extends AbstractBaseDao<Function> implements FuncDao {

	/**
	 * 获取全部功能和模块 并分别封装
	 * @param modules 模块列表
	 * @param funcs  功能列表
	 * @author mwei
	 */
	public void getAll(final ArrayList<Function> modules,final ArrayList<Function> funcs) {
		JdbcTemplate template = this.getJdbcTemplate();
		String sql = "SELECT * FROM SYS_FUNCTION T WHERE FLAG='1' ORDER BY T.FUNC_CODE ";	
		template.query(sql, new RowCallbackHandler() {
			public void processRow(ResultSet rs) throws SQLException {
				Function function = new Function();
				function.setCode(rs.getInt("FUNC_CODE"));
				function.setName(rs.getString("FUNC_NAME"));
				function.setType(rs.getString("FUNC_TYPE"));
				function.setSummary(rs.getString("SUMMARY"));
				function.setFlag(rs.getString("FLAG"));
				if(function.getCode()%100==0)
					modules.add(function);
				else
					funcs.add(function);
			}
		});
	}
}
